package com.antler.smt.admin.controller;

import com.antler.smt.admin.annotation.OperateCut;
import com.antler.smt.entity.SupplierEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.request.admin.GetSupplierListReq;
import com.antler.smt.request.base.BasePageReq;
import com.antler.smt.response.admin.GetSupplierListResp;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.SupplierService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务商Controller
 *
 * @author zhangyi
 * @date 2018/3/26 14:40
 */
@RestController
@RequestMapping("/supplierBack")
@Api(description = "后台服务商控制")
public class SupplierController {

    /**
     * 日志
     */
    private static Logger log = LogUtil.get();

    @Resource
    private SupplierService supplierService;

    /**
     * 获取服务商列表
     *
     * @return Result实体
     */
    @PostMapping("/listSupplier")
    @ApiOperation(value = "获取服务商列表(传入的是分页数据)", httpMethod = "POST")
    public Result<Page<GetSupplierListResp>> listSupplier(@RequestBody GetSupplierListReq request) {

        DataValidator.isNull(request,"服务商实体不能为空！");

        Result result = null;
            result = supplierService.getSupplierList(request);
        return result;
    }

    /**
     * 获取服务商详情
     *
     * @return
     */
    @PostMapping("/getSupplierInfo/{id}")
    @ApiOperation(value = "获取服务商详情", httpMethod = "POST")
    public Result<SupplierEntity> getSupplierInfo(@PathVariable Long id) {

        DataValidator.isBlank(String.valueOf(id),"服务商id不能为空！");

        Result result = null;
            result = supplierService.getSupplierInfo(id);
        return result;
    }

    /**
     * 获取服务商入驻审核各个状态的列表
     *
     * @return
     */
    @PostMapping("/getSupplierSettledList")
    @ApiOperation(value = "获取服务商入驻审核各个状态的列表（0未申请 1已申请未审核 2审核通过 3审核未通过）", httpMethod = "POST")
    public Result<Page<GetSupplierListResp>> getSupplierSettledList(@RequestBody GetSupplierListReq request) {

        DataValidator.isNull(request,"服务商入住实体不能为空！");

        Result result = null;
            result = supplierService.getSupplierSettledList(request);
        return result;
    }

    /**
     * 服务商入驻审核
     *
     * @return
     */
    @PostMapping("/supplierSettled/{id}/{settledAuditResult}")
    @ApiOperation(value = "服务商入驻审核", httpMethod = "POST")
    @OperateCut(content = "服务商入驻审核")
    public Result<ResultCodeEnum> supplierSettled(@PathVariable Long id, @PathVariable Integer settledAuditResult) {

        DataValidator.isBlank(String.valueOf(id),"服务商id不为空");
        DataValidator.isBlank(String.valueOf(settledAuditResult),"审核结果不为空！");

        Result result = null;
            result = supplierService.updateSupplierSettled(id,settledAuditResult);
        return result;
    }

    /**
     * 优质服务商认证待审核列表:
     * 0未申请 1已经申请未审核 2审核通过 3审核未通过
     *
     * @param auditResult 审核状态
       @param request 用于分页
     * @return
     */
    @PostMapping("/excellentAuditList/{auditResult}")
    @ApiOperation(value = "优质服务商认证待审核列表:0未申请 1已经申请未审核 2审核通过 3审核未通过", httpMethod = "POST")
    public Result<Page<GetSupplierListResp>> excellentAuditList(@PathVariable Integer auditResult,@RequestBody GetSupplierListReq request) {

        DataValidator.isBlank(String.valueOf(auditResult),"审核结果不为空！");
        DataValidator.isNull(request,"服务商分页实体不为空！");

        Result result = null;
            result = supplierService.getExcellentSupplierList(auditResult,request);
        return result;
    }

    /**
     *  优质服务商认证审核
     *
     * @param id 审核服务商id
     * @param auditResult 审核结果 0未申请 1已经申请未审核 2审核通过 3审核未通过
     * @return
     */
    @PostMapping("/excellentAudit/{id}/{auditResult}")
    @ApiOperation(value = "优质服务商认证审核", httpMethod = "POST")
    public Result<ResultCodeEnum> excellentAudit(@PathVariable Long id, @PathVariable Integer auditResult) {

        DataValidator.isBlank(String.valueOf(id),"服务商id不为空！");
        DataValidator.isBlank(String.valueOf(auditResult),"服务商审核结果不为空！");

        Result result = null;
            result = supplierService.excellentAudit(id,auditResult);
        return result;
    }
    /**
     *  获取服务商优质已审核列表（审核通过和未通过）
     *
     * @return
     */
    @PostMapping("/supplierWaitAuditList")
    @ApiOperation(value = "获取服务商优质已审核列表(传入的是分页数据)", httpMethod = "POST")
    public Result<Page<GetSupplierListResp>> supplierWaitAuditList(@RequestBody BasePageReq basePageReq) {

        Result result = null;
            result = supplierService.selectEndExcellentAudit(basePageReq);
        return result;
    }
    /**
     *  获取入住服务商已审核列表（审核通过和未通过）
     *
     * @return
     */
    @PostMapping("/supplierEndAuditList")
    @ApiOperation(value = "获取入住服务商已审核列表(传入的是分页数据)", httpMethod = "POST")
    public Result<Page<GetSupplierListResp>> supplierEndAuditList(@RequestBody BasePageReq basePageReq) {

        Result result = null;
            result = supplierService.selectEndSetted(basePageReq);
        return result;
    }

    /**
     *  服务商信息修改
     *
     * @param supplierId 服务商id
     * @return
     */
    @PostMapping("/editSupplierInfo")
    @ApiOperation(value = "服务商信息修改（星级和规模）", httpMethod = "POST")
    @OperateCut(content = "服务商信息修改（星级和规模）")
    public Result<ResultCodeEnum> editSupplierInfo(@RequestParam(value = "supplierId") Long supplierId ,@RequestBody GetSupplierListReq request) {

       DataValidator.isBlank(String.valueOf(supplierId),"服务商的id不能为空！");
       DataValidator.isNull(request,"修改的服务商实体不能为空！");

        Result result = null;
            result = supplierService.editSupplierInfo(supplierId,request);
        return result;
    }

    /**
     *  服务商账户冻结
     *
     * @param supplierId 服务商id
     * @return
     */
    @PostMapping("/freezeSupplier")
    @ApiOperation(value = "服务商账户冻结", httpMethod = "POST")
    @OperateCut(content = "服务商账户冻结")
    public Result<ResultCodeEnum> freezeSupplier(@RequestParam(value = "supplierId") Long supplierId,
                                                 @RequestParam(value = "status") Integer status) {
        DataValidator.isBlank(String.valueOf(supplierId),"服务商id不能为空！");

        Result result = null;
            result = supplierService.freezeSupplier(supplierId,status);
        return result;
    }
}
